package com.ycsj.goldmedalnewconcept.activity;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.res.AssetManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ListView;
import android.widget.TextView;

import com.readystatesoftware.systembartint.SystemBarTintManager;
import com.ycsj.goldmedalnewconcept.bean.UserVedioListInfo;
import com.ycsj.goldmedalnewconcept.fragment.MineShoucangTestFragment;
import com.ycsj.goldmedalnewconcept.fragment.MineShoucangVideoFragment;
import com.ycsj.goldmedalnewconcept.ui.SegmentView;
import com.ycsj.goldmedalnewconcept.ui.SegmentView.OnSegmentSelectedListener;
import com.ycsj.goldmedalnewconcept.R;

@SuppressLint("NewApi")
public class MineShoucangActivity extends BaseJpStarActivity {

	private ArrayList<UserVedioListInfo> leftNums=new ArrayList<UserVedioListInfo>();
	private ArrayList<UserVedioListInfo> rightNums=new ArrayList<UserVedioListInfo>();

	Boolean svselect=true;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_mine_shoucang);
		
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
			setTranslucentStatus(true);
		}
		SystemBarTintManager tintManager = new SystemBarTintManager(this);
		tintManager.setStatusBarTintEnabled(true);
		tintManager.setStatusBarTintResource(R.color.base_color);
		
		init();
	}

	protected void init() {
		tv_main_back = (TextView) findViewById(R.id.tv_main_back);
		
		 
		lv_favor = (ListView) findViewById(R.id.lv_favor);
		sv = (SegmentView) findViewById(R.id.sv);
		sv.setOnSegmentSelectedListener(listener);
		
		FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
		ft.replace(R.id.shoucang_fragment_container, new MineShoucangVideoFragment()).commit();
		
		AssetManager mgr=getAssets();//得到AssetManager
//		Typeface tf=Typeface.createFromAsset(mgr, "fonts/title.TTF");//根据路径得到Typeface
//		tv_main_back.setTypeface(tf);
		
		tv_main_back.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}

	
	private OnSegmentSelectedListener listener=new OnSegmentSelectedListener() {
		
		
		@Override
		public void onSegmentSelected(boolean isUnlockSelected) {
			if(isUnlockSelected){
//				Toast.makeText(MineShoucangActivity.this, "左", 0).show();
				FragmentTransaction ft =  getSupportFragmentManager().beginTransaction();
				ft.replace(R.id.shoucang_fragment_container, new MineShoucangTestFragment()).commit();
				svselect=true;
				
			}else{
//				Toast.makeText(MineShoucangActivity.this, "右", 0).show();
				FragmentTransaction ft =  getSupportFragmentManager().beginTransaction();
				ft.replace(R.id.shoucang_fragment_container, new MineShoucangVideoFragment()).commit();
				svselect=false;
				}
			
		}
	};
	
	private ListView lv_favor;
	private TextView tv_main_back;
	private SegmentView sv;
	


	@Override
	protected void onResume() {
		super.onResume();
		if(svselect){
			
			sv.settvtrue();
		}
//		FragmentTransaction ft =  getSupportFragmentManager().beginTransaction();
//		ft.replace(R.id.shoucang_fragment_container, new MineShoucangTestFragment()).commit();
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
//		finish();
		super.onStop();
	}
	
	
	
	@TargetApi(19) 
	private void setTranslucentStatus(boolean on) {
		Window win = getWindow();
		WindowManager.LayoutParams winParams = win.getAttributes();
		final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
		if (on) {
			winParams.flags |= bits;
		} else {
			winParams.flags &= ~bits;
		}
		win.setAttributes(winParams);
	}
	
		
	
}
